"""
@author: zwz
@file: 11.实现Linux的tree命令效果.py
@time: 2022/11/24 0024 16:33:05
"""

import os
import os.path


def tree(path, depth=0):
    if depth == 0:
        print(path)
    items = os.listdir(path)
    print(items)
    for item in items:
        # 输出文件夹中的文件和子文件夹名
        print('|    ' * depth, end='')
        print('|----', item)
        item = os.path.join(path, item)
        if os.path.isdir(item):
            # 递归遍历子目录
            tree(item, depth + 1)
tree(r'..')